package com.ys.erp.stage_mall_service.controller;

import com.ys.erp.framework.annotation.CheckEmpLogin;
import com.ys.erp.framework.annotation.RedissonLock;
import com.ys.erp.framework.annotation.ResponseResult;
import com.ys.erp.framework.annotation.StageLoginEmp;
import com.ys.erp.framework.bean.dto.StageEmpDTO;
import com.ys.erp.framework.response.PageDTO;
import com.ys.erp.stage_mall_service.bean.condition.AfterSaleCondition;
import com.ys.erp.stage_mall_service.bean.vo.OrderAfterSaleVO;
import com.ys.erp.stage_mall_service.service.AfterSaleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import jakarta.validation.Valid;

/**
 * @author lwj
 * @date 2025/5/20
 */
@ResponseResult
@RestController
@RequiredArgsConstructor
@RequestMapping("/manage/mall/order/afterSale")
@Tag(name = "订单售后相关接口", description = "订单售后相关接口")
public class AfterSaleController {

    private final AfterSaleService afterSaleService;

    @PostMapping("refundToShopOrder")
    @CheckEmpLogin
    @Operation(description = "到店订单退款")
    @RedissonLock(key = "#con.orderNo")
    public void refundToShopOrder(@RequestBody AfterSaleCondition.RefundToShopOrderCon con,
                                  @StageLoginEmp StageEmpDTO empDTO) {
        afterSaleService.refundToShopOrder(empDTO, con);
    }

    @PostMapping("/pageOrderAfterSale")
    @CheckEmpLogin
    @Operation(description = "分页售后订单")
    public PageDTO<OrderAfterSaleVO> pageOrderAfterSale(@RequestBody AfterSaleCondition.PageOrderAfterSaleCon con,
                                                        @StageLoginEmp StageEmpDTO empDTO) {
        return afterSaleService.pageOrderAfterSale(empDTO, con);
    }

    @PostMapping("/refundPulseByAfterSale")
    @CheckEmpLogin
    @Operation(description = "通过售后单退还幺豆")
    @RedissonLock(key = "#con.afterSaleId")
    public void refundPulseByAfterSale(@RequestBody @Valid AfterSaleCondition.RefundPulseByAfterSaleCon con,
                                      @StageLoginEmp StageEmpDTO empDTO) {
        afterSaleService.refundPulseByAfterSale(empDTO, con);
    }

}
